# @Author : Labyrinthine Leo
# @Time   : 2020.11.25
# @problem: KUR
# Benchmark MOP proposed by
################################## Reference ################################
#                                                                           #
#############################################################################

import numpy as np
import platgo as pg


class KUR(pg.Problem):

    def __init__(self, D: int = 3) -> None:
        self.name = "KUR"
        self.type['single'], self.type['real'] = [True] * 2
        self.M = 2
        self.D = D
        lb = [-5] * self.D
        ub = [5] * self.D
        self.borders = np.array([lb, ub])
        super().__init__()

    def cal_obj(self, pop: pg.Population) -> None:
        decs = pop.decs
        f1 = np.sum(-10 * np.exp(-0.2 * np.sqrt(decs[:, :-1]**2 + decs[:, 1:]**2)), axis=1, keepdims=True)
        f2 = np.sum((np.abs(decs))**0.8 + 5*np.sin(decs**3), axis=1, keepdims=True)
        pop.objv = np.hstack((f1, f2))

    def get_optimal(self) -> np.ndarray:
        # 参考点采样
        raise NotImplementedError("get optimal has not been implemented")


if __name__ == '__main__':
    k = KUR(D=10)
    pop = pg.Population(decs=np.random.uniform(k.borders[0], k.borders[1], (10, 10)))
    print(k.borders)
    print(pop.decs)
    k.cal_obj(pop)
    print(pop.objv)


